//引入express模块
const express = require("express"); //引过来的express是一个函数
const goodsRouter = require("./routes/goods");
const loginRouter = require("./routes/login");
const ordersRouter = require("./routes/orders");
const operateRouter = require("./routes/operate");
const jurisdictionRouter = require("./routes/jurisdiction");
const adminRouter = require("./routes/admin");
const userList = require("./routes/user_list");
const Statistics = require("./routes/goodst");
const promotion = require("./routes/promotion");
const imgapi = require("./routes/imgApi");
const ReturnordersRouter = require("./routes/ReturnOrders");
const WxRouter = require("./routes/wx");
const wxorders = require("./routes/wxorder");

//创建服务
const app = express(); //调用得到服务

//修改参入参数的大小限制
var bodyParser = require("body-parser");
//handle request entity too large
app.use(
    bodyParser.json({
        limit: "50mb",
    })
);
app.use(
    bodyParser.urlencoded({
        limit: "50mb",
        extended: true,
    })
);
//请求头的数据类型为 x/www-form-urlencoded
app.use(express.json()); //请求数据以json格式为主

/* CORS  解决跨域问题 */
/* 拦截所有请求，给他一个处理函数 */
app.all("*", function (req, res, next) {
    /* 设置响应头，允许所有网站都可以请求 */
    res.header("Access-Control-Allow-Origin", "*");
    /* 设置我们的请求方式可以有以下这些 */
    res.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
    /* 设置响应头可以有以下这些 */
    res.header(
        "Access-Control-Allow-Headers",
        "Content-Type,Content-Length, Authorization, Accept,X-Requested-With"
    );
    /* 放行 */
    next();
});

//使用接口文件
app.use(goodsRouter);
app.use(loginRouter);
app.use(ordersRouter);
app.use(operateRouter);
app.use(jurisdictionRouter);
app.use(adminRouter);
app.use(userList);
app.use(Statistics);
app.use(promotion);
app.use(imgapi);
app.use(ReturnordersRouter);
app.use(WxRouter);
app.use(wxorders);
//配置端口号
// 1-65535  但是  1000一下 一般都为系统的保留端口号 一般不用
//默认的端口号是80  浏览器就不用输入端口号了。
app.listen(8888);
